<?php

defined( 'IN_DICE' ) or die( 'Access Error!' );

include_once( DIR_MDL . 'platform/platform.php' );
include_once( DIR_MDL . 'platform/class.manyou.php' );

class pmanyou implements platform {
	
	/**
	 * @var Manyou
	 */
	public $op;
	public $pfid;
	public $apiid;
	public $apikey;
	public $apisecret;
	public $apiurl;
	
	public function __construct(){
		$this->pfid = all::$cfg['manyou_pfid'];
		$this->apiid = all::$cfg['manyou_apiid'];
		$this->apikey = all::$cfg['manyou_apikey'];
		$this->apisecret = all::$cfg['manyou_apisecret'];
		$this->apiurl = all::$cfg['manyou_apiurl'];
		$this->op = new Manyou( all::$cfg['manyou_apikey'], all::$cfg['manyou_apisecret'] );
	}
	public function getUserId(){ //错误则返回空字符串
		$puid = $this->op->api_client->user_getLoggedInUser();
		return strlen( $puid ) ? $puid : '';
	}
	public function getUserInfo( $puid ) {
		$uinfo = $this->op->api_client->user_getinfo( $puid, array('uid','uch_id','name','handle','site','sex','birthday','current_location','hometown_location','admin_level'));
		$uinfo = $uinfo[0]; //二维数组
		return ( strcmp($puid, $uinfo['uid']) !== 0) ? array() : array( //错误则返回空数组,否则严格返回以下格式
																	'puid' => $uinfo['uid'],
																	'uname' => $uinfo['name'] ? $uinfo['name'] : $uinfo['handle'],
																	'headurl' => "http://uchome.manyou.com/avatar/{$puid}?thumb",
																	'sex' => $uinfo['sex'] == 'male' ? 1 : ( $uinfo['sex'] == 'famale' ? 0 : 2 ),
																	'psuid' => $uinfo['uch_id'],
																	'upage' => "http://uchome.manyou.com/profile/{$puid}",
																	'usid' => $uinfo['site'],
																	'pfid' => all::$cfg['manyou_pfid'],
																	);
	}
	public function getAllFriends(){
		$list = $this->op->api_client->friend_get();
		return is_array($list) ? $list : array();
	}
	public function getAppFriends(){
		$list = $this->op->api_client->friend_getAppUsers();
		return is_array($list) ? $list : array();
	}
	public function isAdded(){ // 检测用户是否已添加应用 
		$this->op->require_add();
	}
	public function getSiteInfo(){
		
	}
	public function sendNotice(){
		
	}
	public function sendFeed( $aFields ) {
		
	}
	public function setProfile(){
		
	}
	public function setKey( $key ){
		$this->op->api_client->session_key = $key;
	}
}